//刷新表单
function renderForm() {
    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
}

/**
 * 清空form表单
 * @param formId
 */
function cleanForm(formId) {
    document.getElementById(formId).reset();
}

/**
 *
 * @requires jQuery
 *
 * 将form表单元素的值序列化成对象
 *
 * @returns object
 */
function serializeObject(form) {
    var o = {};
    $.each(form.serializeArray(), function (index) {
        if (o[this['name']]) {
            o[this['name']] = o[this['name']] + "," + this['value'];
        } else {
            o[this['name']] = this['value'];
        }
    });
    return o;
}

/**
 * 获取地址参数
 * @param name
 * @returns {string|null}
 * @constructor
 */
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    //alert(r)
    if (r != null) return unescape(r[2]);
    return null;
}

function isIE() {
    //获取当前使用的浏览器的型号
    var explorer = window.navigator.userAgent.toLowerCase();
    if (explorer.indexOf("trident") >= 0) {
        return true;
    } else {
        return false;
    }
}

/**
 * 重写ajax
 */
(function ($) {
    var _ajax = $.ajax;
    $.ajax = function (url, opt) {
        layer.load(2);
        if ("object" == typeof url) {
            opt = url;
        } else {
            opt = {url: url};
        }
        opt.cache = opt.cache || true;
        if (opt.type == 'GET' || opt.type == 'get') {
            opt.cache = false;
        }
        opt.type = opt.type || 'post';
        opt.data = opt.data || {};
        opt.dataType = opt.dataType || 'JSON';
        var fn = {
            error: opt.error,
            success: opt.success
        };
        opt.error = function (XMLHttpRequest, textStatus, errorThrown) {
            layer.closeAll('loading');
            if (fn.error) {
                fn.error(XMLHttpRequest, textStatus, errorThrown);
            } else if (XMLHttpRequest.message) {
                layer.alert(XMLHttpRequest.message);
            } else {
                layer.alert(opt.url + "超时或系统异常");
            }
        };
        opt.success = function (data, textStatus, jqXHR) {
            layer.closeAll('loading');
            if (fn.success) {
                fn.success(data, textStatus, jqXHR);
            } else if (data.message) {
                if (data.code == "1") {
                    layer.closeAll()
                    layer.msg(data.message, {time: 2000});
                } else {
                    layer.alert(data.message)
                }
            } else if (opt.statusCode == 200) {
                layer.msg('操作成功', {time: 2000});
            }
        };
        return _ajax(opt);
    };
})(jQuery);

function get_win_innerHeight() {
    if (window.innerHeight != undefined)
        return window.innerHeight;
    else
        return document.documentElement.clientHeight;
}